# -*- coding:utf-8 -*-
'''
通过一个类来实现 分数
'''
class Fraction:
    def __init__(self, top, bottom):
        self.num = top
        self.den = bottom

    def show(self):
        print(self.num, "/", self.den, sep = '')

    def __str__(self):
        return str(self.num) + "/" + str(self.den)
    
    def __add__(self, other):
        newnum = self.num * other.den + other.num * self.den
        newden = self.den * other.den
        common = gcd(newnum, newden)
        return Fraction(newnum//common, newden//common)
    
    def __eq__(self, other):
        return self.num * other.den == other.num * self.den


# 欧几里得算法：两个整数的最大公约数等于其中较小的数和两数相除余数的最大公约数。
def gcd(a, b):
    while b != 0:
        a, b = b, a%b
    return a

f1 = Fraction(1, 2)
f2 = Fraction(2, 4)
print(f1 == f2)